const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(cc.Node)
    other: cc.Node = null;

    @property
    speed: number = 0;

    onLoad () {
        if(this.other == null){ //当这个为空时
            cc.log("roll other is null") //提示开发者资源为空
            this.enabled = false
        }
    }

    
    update (dt) {
        let trigger = this.node.width
        if(this.node.x < -trigger){
            this.node.x = this.other.x + trigger
        }
        if(this.other.x < -trigger){
            this.other.x = this.node.x + trigger
        }
        this.node.x += this.speed*dt
        this.other.x += this.speed*dt
    }
}
